/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package top.continew.admin.zxr.service.impl;

import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.ContentType;
import cn.hutool.json.JSONUtil;

import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;

import lombok.extern.slf4j.Slf4j;
import net.dreamlu.mica.core.result.R;
import org.springframework.stereotype.Service;

import org.springframework.web.multipart.MultipartFile;
import top.continew.admin.zxr.model.req.XshtbImportReq;
import top.continew.admin.zxr.model.resp.XshtbImportParseResp;
import top.continew.admin.zxr.model.resp.XshtbImportResp;
import top.continew.starter.extension.crud.service.BaseServiceImpl;
import top.continew.admin.zxr.mapper.XshtbMapper;
import top.continew.admin.zxr.model.entity.XshtbDO;
import top.continew.admin.zxr.model.query.XshtbQuery;
import top.continew.admin.zxr.model.req.XshtbReq;
import top.continew.admin.zxr.model.resp.XshtbDetailResp;
import top.continew.admin.zxr.model.resp.XshtbResp;
import top.continew.admin.zxr.service.XshtbService;
import top.continew.starter.web.util.FileUploadUtils;

import java.io.IOException;
import java.time.LocalDateTime;

/**
 * 销售合同业务实现
 *
 * @author yfh
 * @since 2025/05/06 14:42
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class XshtbServiceImpl extends BaseServiceImpl<XshtbMapper, XshtbDO, XshtbResp, XshtbDetailResp, XshtbQuery, XshtbReq> implements XshtbService {
    /**
     * 下载导入模板
     *
     * @param response
     */
    @Override
    public void downloadImportTemplate(HttpServletResponse response) throws IOException{
        try {
            FileUploadUtils.download(response, ResourceUtil.getStream("templates/import/xshtb.xlsx"), "销售合同导入模板.xlsx");
        } catch (Exception e) {
            log.error("下载销售合同导入模板失败：{}", e.getMessage(), e);
            response.setCharacterEncoding(CharsetUtil.UTF_8);
            response.setContentType(ContentType.JSON.toString());
            response.getWriter().write(JSONUtil.toJsonStr(R.fail("下载销售合同导入模板失败")));
        }
    }

    /**
     * 解析导入数据
     *
     * @param file
     */
    @Override
    public XshtbImportParseResp parseImport(MultipartFile file) {
        return null;
    }

    /**
     * 导入数据
     *
     * @param req
     */
    @Override
    public XshtbImportResp importXshtb(XshtbImportReq req) {
        return null;
    }

    /**
     * 初审通过
     *
     * @param id
     */
    @Override
    public void chushenTg(Long id) {
        baseMapper.lambdaUpdate().set(XshtbDO::getShztbm,1).set(XshtbDO::getShry,"").set(XshtbDO::getShrq, LocalDateTime.now()).eq(XshtbDO::getId,id).update();
    }

    /**
     * 初审退回
     *
     * @param id
     * @param reason
     */
    @Override
    public void chushenTh(Long id, String reason) {

    }

    /**
     * 终审通过
     *
     * @param id
     */
    @Override
    public void zhongshenTg(Long id) {

    }

    /**
     * 终审退回
     *
     * @param id
     * @param reason
     */
    @Override
    public void zhongshenTh(Long id, String reason) {

    }
}